import random
from urllib import request, parse

url = "http://httpbin.org/post"

UserAgentFromFirefox = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"
UserAgentFromChrome = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
UserAgentFromQQ = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400"
UserAgentFromIE = "Mozilla/5.0 (MSIE 9.0; qdesk 2.4.1266.203; Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

userAgent = random.choice([UserAgentFromFirefox, UserAgentFromChrome, UserAgentFromQQ, UserAgentFromIE])
#print(userAgent)

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
    "Accept - Encoding": "gzip, deflate",
    "Accept - Language": "zh-CN,zh;q=0.9",
    "Host": "httpbin.org",
    "Upgrade - Insecure - Requests": "1",
    "User - Agent": userAgent
}

dict = {
    "name": "value"
}

data = bytes(parse.urlencode(dict), encoding='utf8')
req = request.Request(url=url, data=data, headers=headers)

response = request.urlopen(req)
print(response.read().decode('utf-8'))
